﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var status = '@ViewBag.status';
    var number = '@ViewBag.number';
    $(function () {
        initControl();
        partsList();
    });
    function initControl() {
        var myLayout = $('#layout').layout({ resizable: false });
        myLayout.sizePane("west", 300);
        if (status == 'U') {
            if ($('#oldEntity').val() != '') {
                var data = JSON.parse($('#oldEntity').val());
                setDataByJson("#form1", data);
            }
        }
        initBindSelect("#form1");

        $('#MaterialNumber1').blur(function () { SetMaterialTolWei1(); });
        $('#MaterialCerWei1').blur(function () { SetMaterialTolWei1(); });
        $('#MaterialNumber2').blur(function () { SetMaterialTolWei2(); });
        $('#MaterialCerWei2').blur(function () { SetMaterialTolWei2(); });
        $('#MaterialNumber3').blur(function () { SetMaterialTolWei3(); });
        $('#MaterialCerWei3').blur(function () { SetMaterialTolWei3(); });
    }
    function partsList() {
        var $partsList = $("#partsList");
        $partsList.dataGrid({
            url: "/BOM/Product/GetPartsJson2",
            height: $(window).height() - 120,
            colModel: [
                { label: '零件编号', name: 'FProductionNO', width: 115, align: 'left', sortable: false },
                { label: '零件名称', name: 'FProductionName', width: 166, align: 'left', sortable: false }
            ],
            pager: "#partsPager",
            sortname: 'FProductionNO asc',
            rownumbers: false,
            viewrecords: true,
            loadComplete: function () {
                if (status == 'I') {
                    $partsList.jqGrid('setSelection', 1);
                }
            },
            onSelectRow: function (rowId) {
                var rowData = $partsList.jqGrid('getRowData', rowId);
                $("#FProductionNO").val(rowData.FProductionNO);
                $("#FProductionName").val(rowData.FProductionName);
            },
            beforeSelectRow: function (rowid, e) {
                if (status != 'I') {
                    return false;
                }
            }
        });
        $("#btn_search").click(function () {
            $partsList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_ok() {
        var MaterialNumber1 = $('#MaterialNumber1').val();
        var MaterialCerWei1 = $('#MaterialCerWei1').val();
        if ((MaterialNumber1 == '' && MaterialCerWei1 != '') || (MaterialNumber1 != '' && MaterialCerWei1 == '')) {
            $.modalAlert("一级余料块数和一级余料单块重量必须都填写或都不填写", "error");
            return;
        }
        var MaterialNumber2 = $('#MaterialNumber2').val();
        var MaterialCerWei2 = $('#MaterialCerWei2').val();
        if ((MaterialNumber2 == '' && MaterialCerWei2 != '') || (MaterialNumber2 != '' && MaterialCerWei2 == '')) {
            $.modalAlert("二级余料块数和二级余料单块重量必须都填写或都不填写", "error");
            return;
        }
        var MaterialNumber3 = $('#MaterialNumber3').val();
        var MaterialCerWei3 = $('#MaterialCerWei3').val();
        if ((MaterialNumber3 == '' && MaterialCerWei3 != '') || (MaterialNumber3 != '' && MaterialCerWei3 == '')) {
            $.modalAlert("三级余料块数和三级余料单块重量必须都填写或都不填写", "error");
            return;
        }

        submitForm();
    }
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        $.submitForm({
            url: "/BOM/Manufacture/SubmitResidueListForm?status=" + status + "&keyValue=" + number,
            param: $("#form1").formSerialize(),
            success: function (result) {
                parent.reloadGrid(result.data);
                parent.$.detailClose();
            }
        })
    }
    function btn_cancel() {
        parent.$.detailClose();
    }
    function SetMaterialTolWei1() {
        var MaterialNumber1 = $('#MaterialNumber1').val();
        var MaterialCerWei1 = $('#MaterialCerWei1').val();
        if (MaterialNumber1 != '' && MaterialCerWei1 != '') {
            $('#MaterialTolWei1').val((parseInt(MaterialNumber1) * parseFloat(MaterialCerWei1)).toFixed(2));
        }
        else {
            $('#MaterialTolWei1').val("");
        }
        SetMaterialTolWei();
    }
    function SetMaterialTolWei2() {
        var MaterialNumber2 = $('#MaterialNumber2').val();
        var MaterialCerWei2 = $('#MaterialCerWei2').val();
        if (MaterialNumber2 != '' && MaterialCerWei2 != '') {
            $('#MaterialTolWei2').val((parseInt(MaterialNumber2) * parseFloat(MaterialCerWei2)).toFixed(2));
        } else {
            $('#MaterialTolWei2').val("");
        }
        SetMaterialTolWei();
    }
    function SetMaterialTolWei3() {
        var MaterialNumber3 = $('#MaterialNumber3').val();
        var MaterialCerWei3 = $('#MaterialCerWei3').val();
        if (MaterialNumber3 != '' && MaterialCerWei3 != '') {
            $('#MaterialTolWei3').val((parseInt(MaterialNumber3) * parseFloat(MaterialCerWei3)).toFixed(2));
        } else {
            $('#MaterialTolWei3').val("");
        }
        SetMaterialTolWei();
    }
    function SetMaterialTolWei() {
        var MaterialTolWei = 0;
        var MaterialTolWei1 = $('#MaterialTolWei1').val();
        if (MaterialTolWei1 != '') { MaterialTolWei += parseFloat(MaterialTolWei1); }
        var MaterialTolWei2 = $('#MaterialTolWei2').val();
        if (MaterialTolWei2 != '') { MaterialTolWei += parseFloat(MaterialTolWei2); }
        var MaterialTolWei3 = $('#MaterialTolWei3').val();
        if (MaterialTolWei3 != '') { MaterialTolWei += parseFloat(MaterialTolWei3); }
        if (MaterialTolWei > 0) {
            $('#MaterialTolWei').val(MaterialTolWei);
        }
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        @RenderPage("~/Views/Shared/_CommonStampingList.cshtml")
    </div>
    <div class="ui-layout-center">
        <input id="oldEntity" type="hidden" value="@ViewBag.oldEntity" />
        <form id="form1">
            <div style="padding-left:20px;">
                <table class="form" style="width:900px;text-align:right;margin:15px;border-bottom:2px solid #ccc;">
                    <tr>
                        <td class="formValue" width="160px;">
                            <div class="btn-group dialog-title">
                                @(ViewBag.status == "U" ? "修改" : "新增")边角余料信息
                            </div>
                        </td>
                        <td class="formValue input-width-185" style="width:420px;">
                            &nbsp;
                        </td>
                        <td style="width: 300px; padding: 5px 10px;">
                            <div class="btn-group" style="margin-right:20px;">
                                <a id="" class="btn btn-primary center-block" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 确认</a>
                            </div>
                            <div class="btn-group">
                                <a id="" class="btn btn-primary center-block" onclick="btn_cancel()"><span class="glyphicon glyphicon-remove"></span> 取消</a>
                            </div>
                        </td>
                    </tr>
                </table>
                <table class="form" style="width: 900px;margin-left:15px;">
                    <tr>
                        <th class="formTitle" style="width:180px;">零件编号</th>
                        <td class="formValue input-width-185" style="width:200px;">
                            <input id="FProductionNO" name="FProductionNO" type="text" class="form-control required" readonly="readonly" value="" />
                            <input id="MaterialID" name="MaterialID" type="hidden" value="" />
                        </td>
                        <th class="formTitle" style="width:110px">&nbsp;</th>
                        <td class="formValue">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">零件名称</th>
                        <td class="formValue input-width-320" colspan="3">
                            <input id="FProductionName" name="FProductionName" type="text" class="form-control" readonly="readonly" value="" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">材质</th>
                        <td class="formValue input-width-185">
                            <input id="MaterialCode" name="MaterialCode" type="text" class="form-control required" value="" />
                        </td>
                        <th class="formTitle">料厚</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialThick" name="MaterialThick" type="text" class="form-control text-right required number" maxlength="5" value="" />&nbsp;<label>cm</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">一级冲压余料块数</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialNumber1" name="MaterialNumber1" type="text" class="form-control text-right digits" />&nbsp;<label>块</label>
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue input-width-40">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">一级冲压余料单块重量</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialCerWei1" name="MaterialCerWei1" type="text" class="form-control text-right number" />&nbsp;<label>kg</label>
                        </td>
                        <th class="formTitle">一级冲压余料总重</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialTolWei1" name="MaterialTolWei1" type="text" readonly="readonly" class="form-control text-right number" />&nbsp;<label>kg</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">二级冲压余料块数</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialNumber2" name="MaterialNumber2" type="text" class="form-control text-right digits" />&nbsp;<label>块</label>
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue input-width-40">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">二级冲压余料单块重量</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialCerWei2" name="MaterialCerWei2" type="text" class="form-control text-right number" />&nbsp;<label>kg</label>
                        </td>
                        <th class="formTitle">二级冲压余料总重</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialTolWei2" name="MaterialTolWei2" type="text" readonly="readonly" class="form-control text-right number" />&nbsp;<label>kg</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">三级冲压余料块数</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialNumber3" name="MaterialNumber3" type="text" class="form-control text-right digits" />&nbsp;<label>块</label>
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue input-width-40">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">三级冲压余料单块重量</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialCerWei3" name="MaterialCerWei3" type="text" class="form-control text-right number" />&nbsp;<label>kg</label>
                        </td>
                        <th class="formTitle">三级冲压余料总重</th>
                        <td class="formValue input-width-105">
                            <input id="MaterialTolWei3" name="MaterialTolWei3" type="text" readonly="readonly" class="form-control text-right number" />&nbsp;<label>kg</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">合计冲压余料总重</th>
                        <td class="formValue input-width-105" colspan="3">
                            <input id="MaterialTolWei" name="MaterialTolWei" type="text" readonly="readonly" class="form-control text-right number" />&nbsp;<label>kg</label>
                        </td>
                    </tr>
                </table>
            </div>
        </form>
    </div>
</div>

